<include file="tool" />
<div id="iconDialog" class="easyui-dialog" title="My Dialog" style="width:675px;height:399px;"   
        data-options="iconCls:'icon-standard-folder-page',buttons:'#iconDialog_tool',closed:true,resizable:true,modal:true,closable:true">   
    

    <div class="easyui-layout" data-options="fit:true">   
      <div id="content" data-options="region:'center',border:false,title:'',href:'__APP__/Admin/Public/icon?page=1',loadingMessage:'正在载入图标……'" style="padding:5px;">
      </div> 
        <div data-options="region:'south',title:'',split:false,border:false" style="height:35px;" >     
            <div class="easyui-pagination" style="border:1px solid #ccc;"
                data-options="total: 1008,pageSize: 250,pageList: [10,20,50,250],onSelectPage: function(pageNumber,pageSize){$('#content').panel('refresh', '__APP__/Admin/Public/icon?page='+pageNumber+'&pageSize='+pageSize);}">
            </div>
        </div>   
      
    </div>  



</div> 
<div id="iconDialog_tool">
    <div class="tool_tip" id="myIcon">请选择合适的图标</div>
    <input type="hidden" id='aIcon'/>
    <input type="hidden" id='inputIcon'/>
    <input type="hidden" id='iconVal'/>
    <a href="#" id="modifyok" class="easyui-linkbutton" data-options="iconCls:'icon-ok'" onclick="setIcon()">确认</a>
    <a href="#" class="easyui-linkbutton"
        data-options="iconCls:'icon-cancel'"
        onclick="javascript:$('#iconDialog').dialog('close')">取消</a>
</div>


<table id="rulelist" data-options="fit:true"></table>

<script>
	$('#rulelist').treegrid({    
    url:'__APP__/Admin/Rule/ruleTree',    
    idField:'id', 
    lines: true,
    rownumbers: true,   
    treeField:'text',
    nowrap : true,
    pagination : true,
    fitColumns : true,
    tool:'tool-rule',  
    autoRowHeight : true, 
    striped : true,//交替行
    singleSelect : true,//只允许选择一行
    border : false,
    columns:[[    
        {field:'id',checkbox : true},
        // {title:'id',field:'id',width:50},   
        // {field:'pid',title:'pid',width:50,align:'center'},    
       
        {field:'text',title:'标题',width:200}, 
        {field:'name',title:'URL',width:200},
        {field:'leixing',title:'类型',width:200,
        formatter: function(value,row,index){
               return ruleLx(value);
            }

    },
       {field:'icon',title:'图标',width:80,align:'center',
        formatter: function(value,row,index){
                if (value){
                  
                    return '<span class="'+value+'" style="width:150px;height:24px;display:inline-block;"></span>';
                }
            }

    } , 
     {field:'odernumber',title:'序号',width:60,align:'center',editor:{type:'numberbox',options:{precision:0}}}  
    ]],
        onDblClickCell : function(field, row) {
                         
                                     // if(field=="ordernumber"){
                                     //   $('#rulelist').treegrid('beginEdit', row.id) 
                                     // }  
                                }    
});
// 新建父菜单窗口
function show_add_mRule(){
        $('#add_Rule_form').form('load', {
            pid:0,
            text : '',
            name:''
        });
            $('#btnNewAuthIcon').linkbutton({    
    iconCls:'icon-standard-exclamation' 
}); 
        $('#add_Rule_dialog').dialog("open").dialog('setTitle', '&nbsp;&nbsp;新建主权限');
}

// 新建子权限窗口
function show_add_sRule(){
    var row = $('#rulelist').treegrid("getSelected");
    if(!row){
        $.messager.alert('新建子权限', '没有选择父节点！', 'info');
      

    }else{

   
            $('#add_Rule_form').form('load', {
            pid:row.id,
            text : '',
            name:''
        });
                       $('#btnNewAuthIcon').linkbutton({    
    iconCls:'icon-standard-exclamation' 
});     
        $('#add_Rule_dialog').dialog("open").dialog('setTitle', '&nbsp;&nbsp;新建子权限');
      
  
           
   
    }    
}

// 新建菜单
function add_Rule(){
    $('#add_Rule_form').form('submit', {

            url : '__APP__/Admin/Rule/addRule',

            success : function(data) {
                $("#rulelist").treegrid("reload");

                $.messager.alert('新建权限', data, 'info');
                $('#add_Rule_dialog').dialog('close')

            }
        });
}
// 删除菜单
function del_Rule(){
      var row = $('#rulelist').treegrid("getSelected");
    if(!row){
        $.messager.alert('删除菜单', '请选择要删除的菜单！', 'info');
      

    }else{

        $.messager.confirm('确认','您确认想要删除“'+row.text+'”吗？',function(r){    
            if (r){    
                $.post('__APP__/Admin/Rule/delRule', {
                            id : row.id
                        }, function(data) {
                            if (data.status==1) {
                                $.messager.alert('删除权限', data.data, 'info');
                                $("#rulelist").treegrid("reload");
                            } else {
                                $.messager.show({ // show error message  
                                    title : '错误',
                                    msg : data.data
                                });

                            }
                        }, 'json');  
            }    
        }); 
           
   
    }    
}

/**
 * 修改菜单窗口
 */
function show_modify_Rule(){
     var row = $('#rulelist').treegrid("getSelected");
    if(!row){
        $.messager.alert('修改菜单', '请选择要修改的菜单！', 'info');
    }else{
             $("#modify_Rule_form").form("load", row);
         if(row.leixing!=1){
            $("#iconFjxg").hide();
        }else{
            $("#iconFjxg").show();
if(row.icon!='' && row.icon){
    $('#btnNewAuthIconxg').linkbutton({    
        iconCls:row.icon
    });  
}else{
 $('#btnNewAuthIconxg').linkbutton({    
        iconCls:'icon-standard-exclamation'
    });
    
}

        }


   
     $("#modify_Rule_dialog").dialog("open").dialog('setTitle', '&nbsp;&nbsp;修改菜单');
           
   
    }   
}
/**
 * 修改菜单
 */
function modify_Rule(){
    
    $('#modify_Rule_form').form('submit', {
    type:'POST',
     url : '__APP__/Admin/Rule/modifyRule',
    success : function(data) {
        $("#rulelist").treegrid("reload");
        $.messager.alert('修改权限', data, 'info');
        $('#modify_Rule_dialog').dialog('close')
        // 

    }
});

}
/**
 * 修改菜单
 */
function ruleLx(val){
    var lx="";
    switch(val)
    {
    case 1:
      lx="菜单";
      break;
     case 2:
      lx="操作";
      break;
    case 3:
      lx="数据";
      break;
    default:
       lx="菜单";
    }
        return lx;
}
</script>